<?php

namespace app\admin\controller\prom;

use app\common\controller\Backend;
use think\Db;

/**
 * 优惠促销
 *
 * @icon fa fa-circle-o
 */
class Promgoods extends Backend
{
    
    /**
     * PromGoods模型对象
     * @var \app\admin\model\PromGoods
     */
    protected $model = null;
    protected $noNeedRight = ['goodslist'];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('PromGoods');
        $this->view->assign("statusList", $this->model->getStatusList());
        $this->view->assign("isEndList", $this->model->getIsEndList());
        $this->view->assign("recommendList", $this->model->getRecommendList());

        $this->view->assign("typeList", $this->model->getTypeList());


    }
    
    //添加促销商品页面
    //$ids 促销活动ID
    public function goodslist($ids){
        $goodsData = $this->model->getGoodsList();

        //  //促销商品列表
        $promGoodsList = $this->model->getPromGoodsList($ids);
        
        $this->assign('promGoodsList',$promGoodsList);

        $this->assign('goodsData',$goodsData);
        $this->assign('id',$ids);
        return $this->view->fetch();
    }

    public function promgoodslist(){
        $ids = $this->request->request('prom_id');
        //促销商品列表
        $promGoodsList = $this->model->getPromGoodsList($ids);
        $this->assign('promGoodsList',$promGoodsList);
         

        // 临时关闭当前模板的布局功能
         $this->view->engine->layout(false); 
         // return $this->display('promgoodslist');
         // return $this->view->fetch();
         return $this->display();
        // return $promGoodsList;

    }

    //添加促销商品
    public function addPromGoods(){
        $goods_id = $this->request->request('goods_id');
        $prom_id = $this->request->request('prom_id');

        $res = Db::name('goods')->where(['id' => $goods_id])->update(['prom_type' => '4','prom_id' => $prom_id]);

        if($res !== false){
            $this->success('添加成功');

        }else{
            $this->error('添加失败');
        }
    }

    public function delPromGoods(){
        $goods_id = $this->request->request('goods_id');
        $res = Db::name('goods')->where(['id' => $goods_id])->update(['prom_type' => '0','prom_id' => 0]);

        if($res !== false){
            $this->success('添加成功');

        }else{
            $this->error('添加失败');
        }

        
    }



    

}
